<template>
    <div>
        <h2>门店显示</h2>
        <div>
            门店id： <select v-model="state.mid">
                <option value="">请选择</option>
                <option value="1">华府城店</option>
                <option value="2">宝格时尚</option>
                <option value="3">美搭</option>
                <option value="4">贝贝乐</option>
                <option value="5">天轩美</option>
              
            </select>
            房型id：<select v-model="state.did">
                <option value="">请选择</option>
                <option value="1">经典普通房</option>
                <option value="2">豪华房</option>
                <option value="3">海景别墅</option>
                <option value="4">豪华海景别墅</option>

            </select>
            <input type="button" value="查询" @click="getlist" >
        </div>
<table class="table table-bordered">
<tr>
    <td>房型名称</td>
    <td>房号</td>
    <td>排序</td>
    <td>门店名称</td>
    <td>状态</td>
    <td>操作</td>
</tr>
<tr v-for="item in list">
    <td>{{item.mid==1?'华府城店':'宝格时尚'}}</td>
    <td>{{item.hId}}</td>
    <td>{{item.orderby}}</td>
    <td>{{item.did==1?'经典普通房':'豪华房'}}</td>
    <td>{{item.state==1?"上架":"下架"}}</td>
    <td>
        <input type="button" v-if="item.state==1" value="下架" @click="upd(item.id,item.state)" >
        <input type="button" v-else="" value="上架" @click="upd(item.id,item.state)" >
        <input type="button"  value="删除" @click="del(item.id)" >
    </td>
</tr>
</table> 
    </div>
</template>

<script setup lang="ts">
import { onMounted, reactive,toRefs } from 'vue';
import { useRouter,useRoute } from 'vue-router';
import axios from 'axios';

const router=useRouter();
let data:any=reactive({
    state:{
did:'',
mid:''

    },
    list:[],
})

let{state,list,totalcount,totalpage}=toRefs(data)

onMounted(()=>{
   
    getlist()
})

const upd=(id:any,state:any)=>{
    if(state==1){
        state=0  
    }
    else{
        state=1
    }
    let obj={
        id: id,
state:state
    }
    axios({
        url:'/api/HouseNum/updsate',
        method:'post',
        params:obj
    })
    .then(res=>{
        console.log(res)
        if(res.data==1){
            alert("修改成功")
            getlist()
        }
        else{
            alert("修改失败")
            return;
        }
    })
    .catch(err=>{
        console.log(err)
    })
}
const del=(id:any)=>{
   var t=confirm("确定要删除吗？")
   if(t){
    let obj={
        id: id,
    }
    axios({
        url:'/api/HouseNum/Del',
        method:'post',
        params:obj
    })
    .then(res=>{
        console.log(res)
        if(res.data==1){
            alert("删除成功")
            getlist()
        }
        else{
            alert("删除失败")
            return;
        }
    })
    .catch(err=>{
        console.log(err)
    })
   }
    
}

const getlist=()=>{
    let obj={
        did:state.value.did,
        mid:state.value.mid,
    }
    axios({
        url:'/api/HouseNum/GetHouseNums',
        method:'get',
        params:obj
    })
    .then(res=>{
        console.log(res)
        list.value=res.data.data

    })
    .catch(err=>{
        console.log(err)
    })
}
</script>

<style scoped>

</style>